<template>
  <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
    <el-form-item label="消息名称" prop="name">
      <el-input v-model="ruleForm.name"/>
    </el-form-item>

    <el-form-item class="infor" label="消息内容" prop="desc">
      <el-input v-model="ruleForm.desc" type="textarea"/>
    </el-form-item>

    <el-form-item label="消息范围" prop="region">
      <el-select v-model="ruleForm.region" placeholder="请选择消息发送范围">
        <el-option label="业主单位" value="shanghai"/>
        <el-option label="维保单位" value="beijing"/>
      </el-select>
    </el-form-item>

    <el-form-item label="发送时间" required>
      <el-col :span="11">
        <el-form-item prop="date1">
          <el-date-picker v-model="ruleForm.date1" type="date" placeholder="选择日期" style="width: 100%;"/>
        </el-form-item>
      </el-col>
    </el-form-item>

    <el-form-item label="定时发送" prop="delivery">
      <el-switch v-model="ruleForm.delivery"/>
    </el-form-item>

    <el-form-item label="消息性质" prop="type">
      <el-checkbox-group v-model="ruleForm.type">
        <el-checkbox label="告警消息" name="type"/>
        <el-checkbox label="测量消息" name="type"/>
        <el-checkbox label="通知消息" name="type"/>
      </el-checkbox-group>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即发送</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入消息名称', trigger: 'blur' },
          { min: 5, max: 8, message: '长度在 5 到 8个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择消息范围', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个消息性质', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写消息内容', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('消息已经发送成功')
        } else {
          console.log('消息已经发送失败')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style type="text/scss" lang="scss">

.el-textarea__inner{
  line-height: 5.5;
}
.el-input--medium .el-input__inner {
    height: 45px;
    line-height: 42px;
}

</style>
